﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace LWH.ByteProtocol
{
    public class ProtocolParseTool
    {
        /**
  * 在byteBuf中查找header
  * @param byteBuf 源数据
  * @param header 匹配的帧头
  * @return 是否匹配成功
  */
        public static bool matchHeader(CircularByteBuffer byteBuf, byte[] header)
        {
            bool isMatch = false;
            int headerLength = header.Length;

            //ByteBuf headerBuf = Unpooled.copiedBuffer(header);

            while (byteBuf.ReadableBytes >= headerLength)
            {

                if (byteBuf.CompareBuffer(header))
                {

                    isMatch = true;
                    break;
                }
                else
                {

                    byteBuf.Clear(1);
                }

            }

            return isMatch;
        }
    }
}
